﻿using System;
using System.Collections.Generic;
using VASJ.Model;
using VASJ.Business;

namespace VASJ.Presentation.HeThong
{
    public partial class FrmNguoiSuDung : DevExpress.XtraEditors.XtraForm
    {
        #region Events

        public FrmNguoiSuDung()
        {
            InitializeComponent();
        }

        private void FrmNguoiSuDung_Load(object sender, EventArgs e)
        {
            LoadResource();
            LoadDataIntoGrid();
        }

        private void btnEditUser_Click(object sender, EventArgs e)
        {
            var selectedRow = grdVUser.GetFocusedRow();
            var frm = new FrmCapNhatNguoiSudung(selectedRow as UserViewModel);
            frm.ShowDialog();
        }

        private void btnAddUser_Click(object sender, EventArgs e)
        {
            var frm = new FrmCapNhatNguoiSudung(new UserViewModel());
            frm.ShowDialog();
        }

        #endregion

        #region Methods
        private void btnDeleteUser_Click(object sender, EventArgs e)
        {
            var selectedRow = grdVUser.GetFocusedRow();
            UserService.DeleteUser(selectedRow as UserViewModel);
        }
        
        private void LoadDataIntoGrid()
        {
            var lstUser = new List<UserViewModel>();
            lstUser.Add(new UserViewModel()
            {
                Id = 1,
                UserName = "Phong",
                Password = "Aod@123",
                Alias = "Mr",
                FullName = "Trần Vương Phong",
                SerialNumber = 1,
                SQLUser = 1,
                Department = "PGD",
                IsManager = true,
                IsInternetAccess = true,
                IsIntranetAccess = true
            }
            );
            lstUser.Add(new UserViewModel()
            {
                Id = 1,
                UserName = "Phong 123",
                Password = "Aod@123",
                Alias = "Mr",
                FullName = "Trần Vương Phong 123",
                SerialNumber = 1,
                SQLUser = 1,
                Department = "PGD",
                IsManager = true,
                IsInternetAccess = true,
                IsIntranetAccess = true
            }
           );

            grdUser.DataSource = lstUser;
        }

        private void LoadResource()
        {
            //LoadResourceOfGrid();
            //LoadResourceOfAllControls();
        }

        private void LoadResourceOfAllControls()
        {
            this.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.Title", "vi-VN");

            lblCurrentUser.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.lblCurrentUser", "vi-VN");
            btnPermisson.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.btnPermission", "vi-VN");
            btnDetail.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.btnDetail", "vi-VN");
            btnEditUser.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.btnEditUser", "vi-VN");
            btnAddUser.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.btnAddUser", "vi-VN");
            btnDeleteUser.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.btnDeleteUser", "vi-VN");
            btnMenu.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.btnMenu", "vi-VN");
            btnDatabase.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.btnDatabase", "vi-VN");
            btnBack.Text = ResourceManager.GetResourceTitle("FrmNguoiSudung.btnQuayra", "vi-VN");
        }

        private void LoadResourceOfGrid()
        {
            grdVUser.Columns[1].Caption = ResourceManager.GetResourceTitle("FrmNguoiSudung.grdVNguoiSuDung.UserName", "vi-VN");
            grdVUser.Columns[2].Caption = ResourceManager.GetResourceTitle("FrmNguoiSudung.grdVNguoiSuDung.Alias", "vi-VN");
            grdVUser.Columns[4].Caption = ResourceManager.GetResourceTitle("FrmNguoiSudung.grdVNguoiSuDung.FullName", "vi-VN");
            grdVUser.Columns[5].Caption = ResourceManager.GetResourceTitle("FrmNguoiSudung.grdVNguoiSuDung.SerialNumber", "vi-VN");
            grdVUser.Columns[6].Caption = ResourceManager.GetResourceTitle("FrmNguoiSudung.grdVNguoiSuDung.SqlUser", "vi-VN");
            grdVUser.Columns[7].Caption = ResourceManager.GetResourceTitle("FrmNguoiSudung.grdVNguoiSuDung.Department", "vi-VN");
        }

        #endregion
    }
}